package cn.xshi.sys.web;

import java.util.List;
import java.util.Map;

import cn.xshi.sys.model.SysDyRemind;
import cn.xshi.sys.model.SysMessage;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import cn.xshi.common.annotation.Auth;
import cn.xshi.common.base.BaseAction;
import cn.xshi.common.base.BaseSearch;
import cn.xshi.sys.model.SysNotifyReceiver;
import cn.xshi.sys.service.SysMessageService;
import cn.xshi.sys.service.SysNotifyReceiverService;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.github.pagehelper.PageInfo;
import javax.annotation.Resource;
/**
 * @Desc 全局动态提醒
 * @Author 邓纯杰
 * @CreateTime 2012-12-12 12:12:12
 */
@RestController
@RequestMapping("/sysDyRemind")
@Api(value = "全局统一动态提醒API",tags = "全局统一动态提醒API",description = "全局统一动态提醒API")
public class SysDyRemindController extends BaseAction {

	@Resource
	private SysNotifyReceiverService sysNotifyReceiverService;

	@Resource
	private SysMessageService sysMessageService;

	/**
	* 加载初始化列表数据并分页
	* @param baseSearch
	* @param receive_status
	*/
	@ApiOperation(value="查询提醒信息", notes="查询提醒信息")
	@PostMapping(value="/list")
	@Auth(value = "/sysDyRemind/list",authenticationType = Auth.AuthorizationType.REQUIRED_LOGIN_NOT_AUTH)
	public SysDyRemind getXtDyRemindList(@RequestBody(required=true)BaseSearch baseSearch, String receive_status){
		SysDyRemind sysDyRemind = new SysDyRemind();
		//处理通知
		Map<String, Object> condition = baseSearch.convert();
		commonHPager(baseSearch);
		condition.put("receiveId", getCurrentAccountId());
		condition.put("status",0);
		List<SysNotifyReceiver> sysNotifyReceiverList = sysNotifyReceiverService.getSysNotifyReceiverListByCondition(condition);
		PageInfo<SysNotifyReceiver> page = new PageInfo<SysNotifyReceiver>(sysNotifyReceiverList);
		sysDyRemind.setSysNotifyReceiverList(page.getList());

		//处理短消息
		condition.put("type", "1");
		condition.put("toId", getCurrentAccountId());
		condition.put("isRead", 0);
		List<SysMessage> xt_MessageList = sysMessageService.getSysMessageListByCondition(condition);
		PageInfo<SysMessage> SysMessage = new PageInfo<SysMessage>(xt_MessageList);
		sysDyRemind.setSysMessageList(SysMessage.getList());
		return sysDyRemind;
	}
}
